#include "TTFont.h"
#include <SDL_ttf.h>
#include <cassert>
#include "Screen.h"

TTFont::TTFont()
{
	m_fontPtr = 0;
	TTF_Init();
}

TTFont::~TTFont()
{
	TTF_CloseFont(m_fontPtr);
}

void TTFont::Draw(const std::string &text, Vec2i pos)
{
	assert(m_fontPtr);
	SDL_Color color = { 255, 255, 255, 255 };
	SDL_Surface* surf = 
		TTF_RenderText_Blended(m_fontPtr,text.c_str(),color);

	SDL_Rect Rectpos;
	Rectpos.x = pos.GetX();
	Rectpos.y = pos.GetY();
	Rectpos.w = 0;
	Rectpos.h = 0;

	SDL_BlitSurface(surf,0 , TheScreen::Instance()->GetScr(),&Rectpos);
	SDL_FreeSurface(surf);
}

bool TTFont::Load(const std::string &fontName, int pointSize)
{
	m_fontPtr = TTF_OpenFont(fontName.c_str(), pointSize);
	return (m_fontPtr != 0);
}